#include #include #include using namespace std; void removePunctuation(string& line) { //replace ' and - with a space //remove all other } bool lineContainsQuery(string line, string query) { //bool result = false; //removePunctuation(line); //line = " " + line + " "; //query = " " + query + " "; //int index = line.find(query); //if(index != string::npos) //{ // result = true; //} //return result; bool result = false; int index = line.find(query); while(index != string::npos) { int queryLength = query.length(); int lineLength = line.length(); if( (index == 0 && lineLength == queryLength) || //line match (index == 0 && (line[index + queryLength] == ' ' || line[index + queryLength] == '-' || line[index + queryLength] == '\'')) || //query was at the beining of the line (index + queryLength == lineLength && line[index-1] == ' ') || //query at the end (index > 0 && line[index + queryLength] == ' ' && line[index-1] == ' ') //query in the middle ) { result = true; } index = line.find(query, index + 1); } return result; } void main() { string query; getline(cin,query); ifstream fin("declaration.txt"); string line; int i = 1; while(!fin.eof()) { getline(fin,line); if(lineContainsQuery(line,query)) { cout << query << "was found on line " << i << endl; } i++; } fin.close(); }